package com.ggk911.pharmacy_system.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ggk911.pharmacy_system.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * 用户
 *
 * @author ggk-911
 * @version 1.0 2023/3/8 10:37
 */
@Repository
public interface UserMapper extends BaseMapper<User> {
    /**
     * 登录方法
     *
     * @param name 用户名
     * @param pwd  用户密码
     * @return 查询到的用户
     */
    @Select("select * from user where user_name = #{user_name} and user_pwd = #{user_pwd}")
    User login(@Param("user_name") String name, @Param("user_pwd") String pwd);

    /**
     * 重写的selectPage方法添加了角色子查询
     * @param page
     * @param queryWrapper
     * @param <P>
     * @return
     */
    @Select("select " +
            "user.*, " +
            "role_id as 'role.roleId', " +
            "role_name as 'role.roleName' " +
            "from " +
            "user " +
            "left join role using (role_id) ${ew.customSqlSegment} ")
    @Override
    <P extends IPage<User>> P selectPage(P page, @Param("ew") Wrapper<User> queryWrapper);

}
